Reproduction Materials for "Gerrymandering and Compactness: Implementation Flexibility and Abuse"
===================================================================================

**Title of Manuscript**:
Gerrymandering and Compactness: Implementation Flexibility and Abuse

**Authors**: Richard Barnes and Justin Solomon

**Corresponding Author**: Richard Barnes (richard.barnes@berkeley.edu)

**DOI Number of Manuscript**: TODO

**Code Repositories**
 * [GitHub Repository](https://github.com/r-barnes/Barnes2019-compactness-flexibility)
 
**Figures Produced**: 17

**Tables Produced**: 1

This repository contains the code needed to produce the figures and data described in the manuscript above.



Abstract
--------

The shape of an electoral district may suggest whether it was drawn with political motivations, or _gerrymandered_. For this reason, quantifying the shape of districts, in particular their compactness, is a key task in politics and civil rights. A growing body of literature suggests and analyzes compactness measures mathematically, but little consideration has been given to how these scores should be calculated in practice. Here, we consider the effects of a number of decisions that must be made in interpreting and implementing a set of popular compactness scores. We show that the choices made in quantifying compactness may themselves become political tools, with seemingly innocuous decisions leading to disparate scores. We show that when the full range of implementation flexibility is used, it can be abused to make clearly gerrymandered districts appear quantitatively reasonable. This complicates using compactness as a legislative or judicial standard to counteract unfair redistricting practices. This paper accompanies the release of packages in C++, Python, and R which correctly, efficiently, and reproducibly calculate a variety of compactness scores.



To Generate Figures
-------------------

Just install the environment and run the `./run` script. Figures will appear the in the `/results` directory.

Figures are known to generate without problems on:

  * A 2011 Thinkpad X201 with a Intel(R) Core(TM) i5 M480@2.67GHz CPU with 4 cores in 1 hour and 7 minutes using a peak of 700MB of RAM.
  
  * Code Ocean's standard AWS r5d.4xlarge instance (a 16-core machine with 120 GB of memory) in about 30 minutes.
  


File List
------------------------

The repository contains the following files:

 * `data/cb_2015_us_cd114_20m.shp`: 20m resolution Congressional District boundaries from "United States Census Bureau. 2016. Cartographic Boundary Shapefiles. https://www.census.gov/geo/maps-data/data/cbf/cbf_cds.html accessed on 2017-08-26."
 * `data/cb_2015_us_cd114_500k.shp`: 500k resolution Congressional District boundaries from "United States Census Bureau. 2016. Cartographic Boundary Shapefiles. https://www.census.gov/geo/maps-data/data/cbf/cbf_cds.html accessed on 2017-08-26."
 * `data/cb_2015_us_cd114_5m.shp`: 5m resolution Congressional District boundaries from "United States Census Bureau. 2016. Cartographic Boundary Shapefiles. https://www.census.gov/geo/maps-data/data/cbf/cbf_cds.html accessed on 2017-08-26."
 * `data/cb_2015_us_state_20m.shp`: 20m resolution state boundaries from "United States Census Bureau. 2016. Cartographic Boundary Shapefiles. https://www.census.gov/geo/maps-data/data/cbf/cbf_cds.html accessed on 2017-08-26."
 * `data/cb_2015_us_state_500k.shp`: 500k resolution state boundaries from "United States Census Bureau. 2016. Cartographic Boundary Shapefiles. https://www.census.gov/geo/maps-data/data/cbf/cbf_cds.html accessed on 2017-08-26."
 * `data/cb_2015_us_state_5m.shp`: 5m resolution state boundaries from "United States Census Bureau. 2016. Cartographic Boundary Shapefiles. https://www.census.gov/geo/maps-data/data/cbf/cbf_cds.html accessed on 2017-08-26."
 * `code/submodules/`: Directory containing `compactnesslib` and `python-mander`, which are used to calculate the compactness scores themselves.
 * `code/tex/`: Directory containing TeX source for several of the figures.
 * `data/pregenerated_output/scores_double_vs_float`: Compactness scores as generated with single- versus double-precision floating-point. This file is presupplied because its effect size is small and generating it takes significant manual work. To generate it, replace `double` with `float` throughout `submodules/compactnesslib/api` and `submodules/compactnesslib/src` and rerun all score generation, per the makefile.
 * `data/pregenerated_output/effect_of_topography.tbl`: Compactness scores as calculated accounting for topography and not. This file is presupplied because its effect size is small and generating it takes significant manual work. To generate it, acquire NED 10m elevation data for the US (several gigabytes), cut the elevation data to the boundary of each congressional district using `gdal`, and then measure the length of the outline with and without topography using RichDEM.
 * `src/augmenter.cpp`: Adds scores to existing shapefiles.
 * `src/CMakeLists.txt`: Part of the build process.
 * `src/common.py`: Functions used my multiple of the scripts in `src/`.
 * `src/districtplot.py`: Plots district silhouettes.
 * `src/koch.cpp`: Generates a Koch snowflake.
 * `src/koch_scores.py`: Calculates scores for a Koch snowflake.
 * `src/make_figs.y`: Generates all of the intermediate figure images.
 * `src/res_bounded.py`: Calculates scores when superunit boundaries are accounted for.
 * `src/res_fig_gerrymandering.py`: Calculates joint effect of many other effects combined.
 * `src/res_projections.py`: Calculates effect of different projections on compactness scores.
 * `src/res_simp_indiv.py`: Calculates effect of simplifying district shapes when each district is considered independently.
 * `src/res_simp_together.py*`: Calculates effect of simplifying district shapes when groups of districts are considered as part of the simplification.
 * `src/Timer.cpp`: Used for timing various operations
 * `src/Timer.hpp`: Used for timing various operations

